package cn.usian.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Configuration
public class KeyResolverConfig {
    /**
     * 基于请求ip限流规则
     * @return
     */
//    @Bean
//    public KeyResolver ipKeyResolver() {
//        return new KeyResolver() {
//            @Override
//            public Mono<String> resolve(ServerWebExchange exchange) {
//                return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
//            }
//        };
//    }

    /***
     * 基于请求路径的限流
     *
     */
    @Bean
    public KeyResolver pathKeyResolver() {
        return exchange -> Mono.just("/consumer/");
    }
}
